﻿
    using Maticsoft.BLL;
    using Maticsoft.Model;

    using System;
    using System.Text;
    using System.Web;
    using System.Web.UI.HtmlControls;

    public partial class WebPage_YingXiao_ShujuXiazai_Youhui : MarketBBasePage
    {


        private void downYouhui(string teamid, string consume)
        {
            StringBuilder builder = new StringBuilder();
            if (consume == "")
            {
                this.SetError("-ERR ERR_NO_DATA");
                base.Response.Redirect("YingXiao_ShujuXiazai_Youhui.aspx");
            }
            else
            {
                builder.Append("<html>");
                builder.Append("<meta http-equiv=content-type content=\"text/html; charset=UTF-8\">");
                builder.Append("<body><table border='1'>");
                builder.Append("<tr>");
                builder.Append("<td>ID</td>");
                builder.Append("<td align='left'>编号</td>");
                builder.Append("<td>用户名</td>");
                builder.Append("<td>密码</td>");
                builder.Append("<td>到期日</td>");
                builder.Append("<td>状态</td>");
                builder.Append("</tr>");
                int num = 1;
                string[] strArray = consume.Split(new char[] { ',' });
                string str = "";
                for (int i = 0; i < strArray.Length; i++)
                {
                    str = str + "'" + strArray[i] + "',";
                }
                str = str.Substring(0, str.Length - 1);
                Maticsoft.BLL.Coupon coupon = new Maticsoft.BLL.Coupon();
                foreach (Maticsoft.Model.Coupon coupon2 in coupon.GetModelList(" Team_id=" + teamid + " and Consume in (" + str + ")"))
                {
                    builder.Append("<tr>");
                    builder.Append("<td>" + num++.ToString() + "</td>");
                    builder.Append("<td align='left'>" + coupon2.Id + "</td>");
                    Maticsoft.Model.UserInfo model = new Maticsoft.BLL.UserInfo().GetModel(coupon2.User_id);
                    if (model != null)
                    {
                        builder.Append("<td>" + model.Username + "</td>");
                    }
                    else
                    {
                        builder.Append("<td>用户不存在</td>");
                    }
                    builder.Append("<td>" + coupon2.Secret + "</td>");
                    builder.Append("<td>" + DateTime.Parse(coupon2.Expire_time.ToString()).ToString("yyyy-MM-dd") + "</td>");
                    if (coupon2.Consume.ToUpper() == "Y")
                    {
                        builder.Append("<td>已使用</td>");
                    }
                    if (coupon2.Consume.ToUpper() == "N")
                    {
                        builder.Append("<td>未使用</td>");
                    }
                    builder.Append("</tr>");
                }
                builder.Append("</table></body></html>");
                base.Response.ClearHeaders();
                base.Response.Clear();
                base.Response.Expires = 0;
                base.Response.Buffer = true;
                base.Response.AddHeader("Accept-Language", "zh-tw");
                base.Response.AddHeader("content-disposition", "attachment; filename=" + HttpUtility.UrlEncode("coupon_" + DateTime.Now.ToString("yyyy-MM-dd") + ".xls", Encoding.UTF8));
                base.Response.ContentType = "Application/octet-stream";
                base.Response.Write(builder.ToString());
                base.Response.End();
            }
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            this.HeaderControl1.Select = "yingxiao";
            this.YingXiao1.Select = "shuju";
            if (base.Request.HttpMethod == "POST")
            {
                if (base.Request.Form["consume[]"] != null)
                {
                    string teamid = base.Request.Form["team_id"].ToString();
                    string consume = base.Request.Form["consume[]"].ToString();
                    this.downYouhui(teamid, consume);
                }
                else
                {
                    this.SetError("-ERR ERR_NO_DATA");
                    base.Response.Redirect("YingXiao_ShujuXiazai_Youhui.aspx");
                }
            }
        }
    }


